<template>
  <view class="swipe-group swipe-group--fix">
    <view v-if="$slots.default" class="swipe-group__wrap">
      <slot />
    </view>
  </view>
</template>

<script lang="ts">
import { defineComponent, provide } from '@vue/composition-api'

export default defineComponent({
  props: {},
  setup() {
    const swipeList: any[] = []
    provide('swipeParent', {
      addSwipe(vm) {
        swipeList.push(vm)
      },
      removeSwipe(vm) {
        const index = swipeList.findIndex((x) => x === vm)

        swipeList.splice(index, 1)
      },
      setShow(vm) {
        swipeList.forEach((item: any) => {
          item.show = vm === item
        })
      },
    })

    const setAllSwipeHide = () => {
      swipeList.forEach((item: any) => {
        item.show = false
      })
    }

    return { setAllSwipeHide }
  },
})
</script>
<style lang="scss" scoped></style>
